﻿/**
 * 说明：第三天，编码案例三MAP练习
 * 时间：2024-07-10
 * 作者：
 */
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
void add_family(map<string, vector<string>>& families, const string& family_name){
    //families这个map添加键值对，family_name如果存在，就不用添加
    if (families.find(family_name) == families.end()) {
        families[family_name] = vector<string>();
    }
}
void add_child(map<string, vector<string>>& families, const string& family_name, const string& child_name){
    //向vector中添加元素
    families[family_name].push_back(child_name);
}
struct DisPlay {
    void operator()(pair<string, vector<string>>info) {
        cout << info.first << "家有小孩: ";
        for (auto& w : info.second) {
            cout << info.first << w << " ";
        }
    }
};
int main()
{
    map<string, vector<string>> families;
    //向failies添加一个家庭
    add_family(families, "张");
    add_child(families, "张", "三");
    add_child(families, "张", "二");
    for_each(families.begin(), families.end(), DisPlay());
}


